function [stateay, stateby, confidenceya, confidenceyb, stateayMult, confidenceyaMult, stateay_bis]=statelp_rz_consec(data,x,hor,rpost,transformation, clevel, opt) 

[~,dsize]=size(data);
stateay     = NaN(dsize,hor);  stateayMult     = NaN(dsize,hor);
stateby     = NaN(dsize,hor);
confidenceya= NaN(2,hor,dsize);confidenceyaMult= NaN(2,hor,dsize);
confidenceyb= NaN(2,hor,dsize);

regy = NaN(size(x,2),dsize);
for j=1:dsize
%   [r,nnn]=size(x);
    
    for i=1:hor
        if transformation==1
            yy=data(i:end,j);
        elseif transformation==2
            yy=(data(i+1:end,j)-data(1:end-i,j))./data(1:end-i,2);
        end
        
        results=nwest(yy, x(1:end-i+1,:),i);
        regy(:,i)=results.beta;
        
        if opt==0
            se(:,i)=results.se';
        else
            [EstCov, hacse, ~]=hac_alt(x(1:end-i+1,:), yy, 'intercept', false, 'smallT', false, 'display', 'off');
            se(:,i)=hacse';
        end

    end
    stateay_bis(j,:)=regy(rpost,:);
    stateay(j,:)    =regy(rpost,:)+regy(rpost+1,:); stateby(j,:)=regy(rpost+2,:)+regy(rpost+2+1,:);
    stateayMult(j,:)=              regy(rpost+1,:); 
    
   %seay         =se(rpost  ,:)+  se(rpost+1,:);    
    seay(    j,:)=se(rpost  ,:); 
    seayMult(j,:)=                se(rpost+1,:);
   %seby         =se(rpost+2,:)+  se(rpost+2+1,:);     
    seby(    j,:)=se(rpost+2,:);
    
    confidenceya(1,:,j)=stateay(j,:)-(seay(j,:)*clevel); 
    confidenceya(2,:,j)=stateay(j,:)+(seay(j,:)*clevel);
    
    confidenceyaMult(1,:,j) = stateayMult(j,:)-(seayMult(j,:)*clevel);
    confidenceyaMult(2,:,j) = stateayMult(j,:)+(seayMult(j,:)*clevel);
    
    confidenceyb(1,:,j)=stateby(j,:)-(seby(j,:)*clevel);
    confidenceyb(2,:,j)=stateby(j,:)+(seby(j,:)*clevel);
end
